﻿<?php
//require_once "config.php";
require_once "common.php";
class register{
	private $username;//用户名
	private $password;//密码
	//构造函数初始化
	function __construct($username,$password){
		$this->username=$username;
		$this->password=$password;
	}
	//自动加载对象
	function __autoload($className){
		require_once("class_".ucfirst($className).".php");
	}
	//用户名验证
	public function chkUsername(){
		$sql="SELECT * FROM user WHERE username='".$this->username."'";
		$mysql=new mysql();
		//$mysql->connect();
		//$mysql->selectdb();
		$result=mysql_query($sql);
		$rows=mysql_num_rows($result);
		//echo mysql_num_rows($mysql->query($sql));
		if($rows>0){
			return false;//用户名重复，不能注册
		}
		return true;//可以注册
	}
	//特殊字符	检测，防sql注入
	public function chk(){
		$username=addslashes($this->username);
		return $username;
	
	}
	//数据库写入
	public function regist(){
		if($this->chkUsername()){
			$this->chk();
			$this->password=md5($this->password);
			$sql="INSERT INTO user(id,username,password) VALUES('','$this->username','$this->password')";
			$mysql=new mysql();
			$res=$mysql->query($sql);
			return $res;
		}
		return false;
	}
	



}



?>